﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using VietTrips.Domain.Contexts;
using VietTrips.Domain.Interfaces;
using VietTrips.Domain.Models;

namespace VietTrips.Domain.Repositories
{
    public class ActivityDetailsRepository : IActivityDetailsRepository
    {

        private ActivityContexts context;

        public ActivityDetailsRepository()
        {
            context = new ActivityContexts();
        }

        public virtual void Dispose()
        {
            if (context != null)
            {
                context.Dispose();
            }

        }

        public IQueryable<ActivityDetail> All {
            get
            {
                return context.ActivityDetails.Where(ad => !ad.IsDeleted);
            }
        }


        public IQueryable<ActivityDetail> AllIncluding(params Expression<Func<ActivityDetail, object>>[] includeExpressions)
        {
            throw new NotImplementedException();
        }

        public ActivityDetail Find(int id)
        {
            return context.ActivityDetails.Find(id);
        }

        public void Insert(ActivityDetail entity)
        {
            context.ActivityDetails.Add(entity);
            this.Save();
        }

        public void Update(ActivityDetail entity)
        {
            context.Entry(entity).State = EntityState.Modified;
            this.Save();
        }

        public void Delete(int id)
        {
            var activityDetail = context.ActivityDetails.Find(id);
            context.ActivityDetails.Remove(activityDetail);
            this.Save();
        }

        public void Save()
        {
            context.SaveChanges();
        }
    }
}
